package com.roc.steelend.controller;


import com.auth0.jwt.interfaces.DecodedJWT;
import com.roc.steelend.controller.vo.common.BuyByRecoding;
import com.roc.steelend.controller.vo.common.KaiPingByRecoding;
import com.roc.steelend.controller.vo.kaiping.KaipingOrderVo;
import com.roc.steelend.controller.vo.returnformat.ReturnMsg;
import com.roc.steelend.controller.vo.returnformat.ReturnMsgForTable;
import com.roc.steelend.pojo.KaipingOrder;
import com.roc.steelend.service.KaipingOrderService;
import com.roc.steelend.util.JWTUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.crypto.interfaces.PBEKey;
import javax.servlet.http.HttpServletRequest;

@RestController
@Api(tags = "开平订单功能接口")
@CrossOrigin
public class KaipingOrderController {

    @Autowired
    private KaipingOrderService kaipingOrderService;

    @PostMapping("/v1/kaiping/submit")
    @ApiOperation(value = "开平订单提交接口",notes = "需要一个详细的信息接收类")
    public ReturnMsg kaipingOrderSubmit(@RequestBody(required = true)KaipingOrderVo kaipingOrderVo, HttpServletRequest request){
        String token = request.getHeader("token");
        DecodedJWT decodedJWT = JWTUtil.getToken(token);
        String employeeIdAsString = decodedJWT.getClaim("employeeId").asString();
        return kaipingOrderService.addKaipingOrderService(kaipingOrderVo,Integer.valueOf(employeeIdAsString));

    }


    //
    @PostMapping("/v1/kaiping/find/recording")
    @ApiOperation(value = "开平查询接口(ps:特殊情况使用post,但不修改数据!!!)",notes = "可选择性填一个所有信息查询器的类(ps:特殊情况使用post,但不修改数据!!!)")
    private ReturnMsgForTable kaipingFindRecoding(@RequestBody(required = false)@ApiParam(value = "条件选择器类",required = false) KaiPingByRecoding selectMsg){

        System.out.println(selectMsg);
        ReturnMsgForTable returnMsgForTable = new ReturnMsgForTable();
        returnMsgForTable.setCurrenPage(selectMsg.getCurrentPage());
        returnMsgForTable.setObjectList( kaipingOrderService.kaipingFindRecoding(selectMsg));
        returnMsgForTable.setTotal(kaipingOrderService.kaipingFindRecodingCount(selectMsg));
        return returnMsgForTable;
    }
}
